/*
* $Id: AddQueenBeeView.cpp 120 2010-07-16 08:16:25Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "AddQueenBeeView.h"
#include "Visual/Drawers/EditorDrawer/HeaderItem.h"
#include "Visual/Drawers/EditorDrawer/EditItem.h"
#include "Visual/Drawers/EditorDrawer/ComboBoxItem.h"
#include "Components/Journal/JournalInterface.h"
#include "Components/Journal/QueenBeeManager.h"

#define TITLE_ID			1
#define NAME_QUEEN_BEE_ID	2
#define DATE_QUEEN_BEE_ID	3
#define BREED_QUEEN_BEE_ID	4
#define FERT_QUEEN_BEE_ID	5
#define STATUS_QUEEN_BEE_ID	6
#define DESCR_QUEEN_BEE_ID	7

CAddQueenBeeView::CAddQueenBeeView(CState* pState)
: CAddChangeView(pState){}
CAddQueenBeeView::~CAddQueenBeeView(){}

void CAddQueenBeeView::SetState(){
	m_pState->m_nState = JournalEnum::VIEW_ADD_QUEEN_BEE;
}

bool CAddQueenBeeView::IsViewState(State state){
	return state.m_type == JournalEnum::ADD_QUEEN_BEE;
}

void CAddQueenBeeView::Init(){
	m_editorDrawer.Clear();
	m_editorDrawer.AddItem(new CHeaderItem(IApplication::GetApp()->GetLanguageManager()->GetString(ADD_QUEEN_BEE_ID), TITLE_ID));
	m_editorDrawer.AddItem(new CEditItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_NAME_QB_ID), NAME_QUEEN_BEE_ID, editItem::TEXT));
	m_editorDrawer.AddItem(new CEditItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_DATE_QB_ID), DATE_QUEEN_BEE_ID, editItem::DATE));
	CComboBoxItem* pItem = new CComboBoxItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_BREED_QB_ID), BREED_QUEEN_BEE_ID);
	for(int i = 1;; i++){
		pItem->AddValueItem(i, IApplication::GetApp()->GetLanguageManager()->GetString(i + BREED_HYBRID_ID));
		if(i + BREED_HYBRID_ID == BREED_FAREAST_ID)
			break;
	}
	pItem->Sort();
	pItem->InsertValueItem(0, 0, IApplication::GetApp()->GetLanguageManager()->GetString(BREED_HYBRID_ID));
	m_editorDrawer.AddItem(pItem);
	m_editorDrawer.AddItem(new CEditItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_STATUS_QB_ID), STATUS_QUEEN_BEE_ID, editItem::BOOL));
	m_editorDrawer.AddItem(new CEditItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_FERT_QB_ID), FERT_QUEEN_BEE_ID, editItem::TEXT));
	m_editorDrawer.AddItem(new CEditItem(IApplication::GetApp()->GetLanguageManager()->GetString(INFO_INSPECT_DESCR_QB_ID), DESCR_QUEEN_BEE_ID, editItem::TEXT));
}

BEGIN_MESSAGE_MAP(CAddQueenBeeView, CAddChangeView)
	ON_COMMAND(BUTTON_SAVE_ID, OnSaveQueenBee)
END_MESSAGE_MAP()

void CAddQueenBeeView::OnSaveQueenBee(){
	IJournalComponent::GetJournalComponent()->GetQueenBeeManager()->AddQueenBee(m_editorDrawer.GetValueItem(NAME_QUEEN_BEE_ID),
		m_editorDrawer.GetValueItem(DESCR_QUEEN_BEE_ID), m_editorDrawer.GetValueItem(FERT_QUEEN_BEE_ID),
		CConvertFunction::ConvertFromDate(m_editorDrawer.GetValueItem(DATE_QUEEN_BEE_ID)),
		(m_editorDrawer.GetValueItem(STATUS_QUEEN_BEE_ID) == _T("+")) ? false : true,
		_ttoi(m_editorDrawer.GetValueItem(BREED_QUEEN_BEE_ID).c_str()),	m_pState->m_nIdParameter);
	__super::OnCancel();
}
